<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-item label="分组">-->
<!--              <a-input placeholder="请输入分组" v-model="queryParam.groupName"></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="组织">
              <j-select-depart placeholder="请选择组织" v-model="queryParam.groupName"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="负责人">
              <!-- <j-select-user-by-dep placeholder="请选择负责人" v-model="queryParam.storeMamager"/> -->
              <j-search-select-multiple-user placeholder="请输入并选择负责人" v-model="queryParam.storeMamager"></j-search-select-multiple-user>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="导入时间">
                <!-- <j-date
                  placeholder="请选择开始日期"
                  class="query-group-cust"
                  v-model="queryParam.createTime_begin"
                ></j-date>
                <span class="query-group-split-cust"></span>
                <j-date
                  placeholder="请选择结束日期"
                  class="query-group-cust"
                  v-model="queryParam.createTime_end"
                ></j-date> -->
                <j-range-picker :begin-date.sync="queryParam.createTime_begin" :end-date.sync="queryParam.createTime_end" :isDisableDateRange="true" :allowClear="false"></j-range-picker>
              </a-form-item>
            </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="店铺名称">
<!--                <a-input placeholder="请输入店铺名称" v-model="queryParam.shopName"></a-input>-->
<!--                <j-single-select-tag type="list_multi" v-model="queryParam.shopName" :options="shopOptions" placeholder="请选择国家" />-->
                <j-search-select-tag v-model="queryParam.shopName" :dict-options="shopOptions" placeholder="请选择店铺" />
              </a-form-item>
            </a-col>
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--              <a-form-item label="站点">-->
<!--                <j-single-select-tag type="list_multi" v-model="queryParam.site" dictCode="finance_amazon_site" placeholder="请选择站点" />-->
<!--              </a-form-item>-->
<!--            </a-col>-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="国家">
                <j-single-select-tag type="list_multi" v-model="queryParam.countryCode" dictCode="lg_finance_amazon_country,country_name,country_code" placeholder="请选择国家" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="来源">
                <j-single-select-tag type="list_multi" v-model="queryParam.source" dictCode="payment_source" placeholder="请选择来源" />
              </a-form-item>
            </a-col>

<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--              <a-form-item label="类型">-->
<!--                <a-input placeholder="请输入类型" v-model="queryParam.type"></a-input>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--              <a-form-item label="描述">-->
<!--                <a-input placeholder="请输入描述" v-model="queryParam.description"></a-input>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="店铺单号">
                <a-input placeholder="请输入店铺单号" v-model="queryParam.saleOrderCode"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button type="primary" icon="download" @click="handleExportXls('亚马逊汇总表')">导出</a-button>
      <!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>  -->
       <a-button type="primary" icon="import" @click="handleImportExcels">导入</a-button> 
       <a-button @click="handleChooseTime" type="primary" icon="calendar" v-has="'financeAmazonOrderConfig:edit'">导入控制</a-button>
       <a-button type="primary" icon="delete" @click="handleDeleteShop">删除</a-button> 
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
<!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange"
        :customRow="selectRowData">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" :preview="0"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

<!--        <span slot="action" slot-scope="text, record">-->
<!--          <a @click="handleEdit(record)">编辑</a>-->

<!--          <a-divider type="vertical" />-->
<!--          <a-dropdown>-->
<!--            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
<!--            <a-menu slot="overlay">-->
<!--              <a-menu-item>-->
<!--                <a @click="handleDetail(record)">详情</a>-->
<!--              </a-menu-item>-->
<!--              <a-menu-item>-->
<!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                  <a>删除</a>-->
<!--                </a-popconfirm>-->
<!--              </a-menu-item>-->
<!--            </a-menu>-->
<!--          </a-dropdown>-->
<!--        </span>-->

        <!-- 字符串超长截取省略号显示-->
        <span slot="description" slot-scope="text, record">
            <j-ellipsis :value="text" :length="20" />
        </span>

      </a-table>
    </div>

    <finance-amazon-order-modal ref="modalForm" @ok="modalFormOk"></finance-amazon-order-modal>
    <finance-amazon-order-import-modal ref="importModalForm" @ok="modalFormOk"></finance-amazon-order-import-modal>
    <finance-amazon-order-config-modal ref="chooseTimeModalForm" @ok="modalFormOk"></finance-amazon-order-config-modal>
    <finance-amazon-order-delete-modal ref="deleteShopModalForm" @ok="modalFormOk"></finance-amazon-order-delete-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixinLG } from '@/mixins/JeecgListMixinLG'
  import FinanceAmazonOrderModal from './modules/FinanceAmazonOrderModal'
  import {getAction} from '@/api/manage'
  import FinanceAmazonOrderImportModal from './modules/FinanceAmazonOrderImportModal'  //导入页面
  import FinanceAmazonOrderConfigModal from './modules/FinanceAmazonOrderConfigModal'  //选择时间
  import FinanceAmazonOrderDeleteModal from './modules/FinanceAmazonOrderDeleteModal'   //删除店铺
  import { colAuthFilter } from "@/utils/authFilter"
  export default {
    name: 'FinanceAmazonOrderList',
    mixins:[JeecgListMixinLG, mixinDevice],
    components: {
      FinanceAmazonOrderModal,
      FinanceAmazonOrderImportModal,
      FinanceAmazonOrderConfigModal,
      FinanceAmazonOrderDeleteModal
    },
    data () {
      return {
        description: '亚马逊汇总表管理页面',
         queryParam:{
            dateBySearch:'createTime',  //查询时间范围字段
          },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'组织',
            align:"center",
            dataIndex: 'groupName_dictText'
          },
          {
            title:'负责人',
            align:"center",
            dataIndex: 'storeMamager'
          },
          {
            title:'店铺名称',
            align:"center",
            dataIndex: 'shopName_dictText'
          },
          // {
          //   title:'站点',
          //   align:"center",
          //   dataIndex: 'site_dictText'
          // },
          {
            title:'国家',
            align:"center",
            dataIndex: 'countryCode_dictText'
          },
          {
            title:'平台结算时间',
            align:"center",
            dataIndex: 'dateWarehouseShipping',
            sorter: true,
          },
          {
            title:'类型',
            align:"center",
            dataIndex: 'type'
          },
          {
            title:'描述',
            align:"center",
            dataIndex: 'description',
            scopedSlots: {customRender: 'description'}
          },
          {
            title:'sku',
            align:"center",
            dataIndex: 'sku'
          },
          {
            title:'数量',
            align:"center",
            dataIndex: 'quantity'
          },
          {
            title:'店铺单号',
            align:"center",
            dataIndex: 'saleOrderCode'
          },
          {
            title:'业务类型',
            align:"center",
            dataIndex: 'orderType_dictText'
          },
          {
            title:'产品金额',
            align:"center",
            dataIndex: 'productAmount'
          },
          {
            title:'产品金额税费',
            align:"center",
            dataIndex: 'productAmountTax'
          },
          {
            title:'客户运费',
            align:"center",
            dataIndex: 'customerFreight'
          },
          {
            title:'客户运费税费',
            align:"center",
            dataIndex: 'customerFreightTax'
          },
          {
            title:'买家支付的礼品包装费',
            align:"center",
            dataIndex: 'giftFee'
          },
          {
            title:'买家支付的礼品包装费税费',
            align:"center",
            dataIndex: 'giftFeeTax'
          },
          {
            title:'亚马逊积分费用',
            align:"center",
            dataIndex: 'amazonIntegralFee'
          },
          {
            title:'折扣促销',
            align:"center",
            dataIndex: 'discount'
          },
          {
            title:'折扣促销税费',
            align:"center",
            dataIndex: 'discountTax'
          },
          {
            title:'亚马逊税费',
            align:"center",
            dataIndex: 'amazonTax'
          },
          {
            title:'平台手续费',
            align:"center",
            dataIndex: 'platformFee'
          },
          {
            title:'FBA手续费',
            align:"center",
            dataIndex: 'fbaFee'
          },
          {
            title:'其他交易费',
            align:"center",
            dataIndex: 'otherFee'
          },
          {
            title:'其他',
            align:"center",
            dataIndex: 'other'
          },
          {
            title:'总共',
            align:"center",
            dataIndex: 'total'
          },
          {
            title:'来源',
            align:"center",
            dataIndex: 'source_dictText'
          },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/amazon/financeAmazonOrder/list",
          delete: "/amazon/financeAmazonOrder/delete",
          deleteBatch: "/amazon/financeAmazonOrder/deleteBatch",
          exportXlsUrl: "/amazon/financeAmazonOrder/exportXls",
          importExcelUrl: "amazon/financeAmazonOrder/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
        shopOptions: []
      }
    },
    created() {
    this.getSuperFieldList();
    this.getListShop();

      this.disableMixinCreated=true;
      this.columns = colAuthFilter(this.columns,'FinanceAmazonOrderList:');
      this.loadData();
      this.initDictConfig();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      selectRowData(record,index){
        const that = this
        return {
          on:{
            dblclick:() => {
              this.handleDetail(record)
            }
          }
        }
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'groupName',text:'分组',dictCode:''})
        fieldList.push({type:'sel_user',value:'storeMamager',text:'负责人'})
        fieldList.push({type:'string',value:'shopName',text:'店铺名称',dictCode:''})
        fieldList.push({type:'number',value:'site',text:'站点',dictCode:''})
        fieldList.push({type:'string',value:'countryCode',text:'国家',dictCode:''})
        fieldList.push({type:'string',value:'dateWarehouseShipping',text:'发货日期',dictCode:''})
        fieldList.push({type:'string',value:'type',text:'类型',dictCode:''})
        fieldList.push({type:'string',value:'sku',text:'sku',dictCode:''})
        fieldList.push({type:'string',value:'description',text:'描述',dictCode:''})
        fieldList.push({type:'string',value:'saleOrderCode',text:'店铺单号',dictCode:''})
        fieldList.push({type:'string',value:'quantity',text:'数量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'productAmount',text:'产品金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'productAmountTax',text:'产品金额税费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'customerFreight',text:'客户运费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'customerFreightTax',text:'客户运费税费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'giftFee',text:'买家支付的礼品包装费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'giftFeeTax',text:'买家支付的礼品包装费税费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'amazonIntegralFee',text:'亚马逊积分费用',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'discount',text:'折扣促销',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'discountTax',text:'折扣促销税费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'amazonTax',text:'亚马逊税费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'platformFee',text:'平台手续费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'fbaFee',text:'FBA手续费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'otherFee',text:'其他交易费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'other',text:'其他',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'total',text:'总共',dictCode:''})
        fieldList.push({type:'number',value:'source',text:'总共',dictCode:'payment_source'})
        this.superFieldList = fieldList
      },
      getListShop() {
        getAction('/amazon/financeAmazonOrder/queryShopList')
          .then((res) => {
            if (res.success) {
              this.shopOptions = res.result
            } else {
              this.$message.error(res.message)
            }
          })
          .catch((err) => {
            this.$message.error(err.message)
          })
          .finally(() => {})
      },
      //导入
      handleImportExcels(){
        this.$refs.importModalForm.title = '导入';
        this.$refs.importModalForm.visible = true;  
      },
      //选择时间
      handleChooseTime(){
        this.$refs.chooseTimeModalForm.title = '选择可导入时间';
        this.$refs.chooseTimeModalForm.visible = true; 
      },
      //删除店铺
      handleDeleteShop(){
        this.$refs.deleteShopModalForm.title = '删除';
        this.$refs.deleteShopModalForm.visible = true;  
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>